public class Solution240 {
    public boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length;
        int n = matrix[0].length;
        int l = 0, r = n - 1;
        for (int[] nums : matrix) {
            if (nums[0] > target) {
                return false;
            }
            while (l <= r) {
                int c = l + (r - l) / 2;
                if (nums[c] == target) {
                    return true;
                } else if (nums[c] < target) {
                    l = c + 1;
                } else {
                    r = c - 1;
                }
            }
            l = 0;
        }
        return false;
    }

}
